include("entity.lua")

//HIDE THE DEFAULT SHIT. WE DON'T WANT TO SEE IT
function hidehud(name)
	for k, v in pairs{"CHudHealth", "CHudBattery","CHudAmmo", "CHudSecondaryAmmo"} do
		if name == v then return false end
	end
end
hook.Add("HUDShouldDraw", "hidehud", hidehud) 
//END HIDE DEFAULT


//CUSTOM HUD
function DrawHUD()	
	local HUDW=200
	local HUDH=100
	local HUDx=0
	local HUDy=ScrH()-HUDH
	local barwidth=100

	draw.RoundedBox( 10, HUDx, HUDy, HUDW, HUDH, Color(0, 0, 0, 180) );

	//DRAWING PARTS
	//these are dependant on above vars. So we should be able to move the hud around
	//NOTE: the if state ments when the health bar is 0, RoundedBox glitches when  width=0, so you have to check for it

	//DRAW HEALTH
	local health=LocalPlayer():Health()
	local maxhealth=100
	local healthbarwidth=health/maxhealth*barwidth
	if(health<0) then health=0 end

	draw.RoundedBox( 4, HUDx+17, HUDy+49, barwidth+6, 5, Color(255, 255, 255, 180) ); //white border
	if(healthbarwidth>1) then
		draw.RoundedBox( 2, HUDx+20, HUDy+50, healthbarwidth, 3, Color(255, 0, 0, 255) ); //red part
	end
	if(healthbarwidth<99) then
		draw.RoundedBox( 2, HUDx+20+healthbarwidth, HUDy+50, barwidth-healthbarwidth, 3, Color(0, 0, 0, 255) ); //black part
	end
	draw.SimpleText(health .. "/"..maxhealth, "ScoreboardText", 130, HUDy+44, Color(86, 104, 86, 255), 0, 0) //text

	//DRAW STAMINA
	local stamina=LocalPlayer():GetNWInt("Stamina")
	local maxstamina=100
	local staminabarwidth=stamina/maxstamina*barwidth
	if(stamina<0) then stamina=0 end

	draw.RoundedBox( 4, HUDx+17, HUDy+61, barwidth+6, 5, Color(255, 255, 255, 180) ); //white border
	if(staminabarwidth>1) then
		draw.RoundedBox( 2, HUDx+20, HUDy+62, staminabarwidth, 3, Color(0, 0, 255, 255) ); //blue part
	end
	if(staminabarwidth<99) then
		draw.RoundedBox( 2, HUDx+20+staminabarwidth, HUDy+62, barwidth-staminabarwidth, 3, Color(0, 0, 0, 255) ); //black part
	end
	draw.SimpleText(stamina .. "/"..maxstamina, "ScoreboardText", 130, HUDy+55, Color(86, 104, 86, 255), 0, 0) //text

	//DRAW HUNGER
	local hunger=LocalPlayer():GetNWInt("Hunger")
	local maxhunger=100
	local hungerbarwidth=hunger/maxhunger*barwidth
	if(hunger<0) then hunger=0 end

	draw.RoundedBox( 4, HUDx+17, HUDy+73, barwidth+6, 5, Color(255, 255, 255, 180) ); //white border
	if(hungerbarwidth>1) then
		draw.RoundedBox( 2, HUDx+20, HUDy+74, hungerbarwidth, 3, Color(160, 32, 240, 255) ); //purple? part
	end
	if(hungerbarwidth<99) then
		draw.RoundedBox( 2, HUDx+20+hungerbarwidth, HUDy+74, barwidth-hungerbarwidth, 3, Color(0, 0, 0, 255) ); //black part
	end
	draw.SimpleText(hunger .. "/"..maxhunger, "ScoreboardText", 130, HUDy+66, Color(86, 104, 86, 255), 0, 0) //text


end
hook.Add("HUDPaint", "DrawHUD", DrawHUD);
//END CUSTOM HUD

function DrawGunAmmo()
	local HUDW=100
	local HUDH=100
	local HUDx=ScrW()-HUDW
	local HUDy=ScrH()-HUDH
	local weight="Error"

	draw.RoundedBox( 10, HUDx, HUDy, HUDW, HUDH, Color(0, 0, 0, 180) );

	if(!ValidEntity(LocalPlayer()) && !ValidEntity(LocalPlayer():GetActiveWeapon())) then return end //bail if we don't have a weapon? (
	
	if(LocalPlayer():GetActiveWeapon().Base== "weap_cs_base") then
		local weapon=LocalPlayer():GetActiveWeapon() 
		draw.SimpleText(weapon:GetNWInt("remainingclips"), "ScoreboardText", HUDx+50, HUDy+66, Color(86, 104, 86, 255), 0, 0)
		local currentclip=weapon:GetNWInt("clip")
		if(currentclip > 0.8*weapon.PrimaryClipSize) then
			weight="HEAVY"
		elseif(currentclip >0.4*weapon.PrimaryClipSize) then
			weight="MEDIUM"
		elseif(currentclip>0) then 
			weight="LIGHT"
		else
			weight="EMPTY"
		end	
	
	elseif(LocalPlayer():GetActiveWeapon().Primary!=nil) then 

		local maxclipsize=LocalPlayer():GetActiveWeapon().Primary.ClipSize
		local currentclipsize=LocalPlayer():GetActiveWeapon():Clip1()
		local reserve=LocalPlayer():GetActiveWeapon():Ammo1()
		
		 //text
		draw.SimpleText(reserve/maxclipsize, "ScoreboardText", HUDx+50, HUDy+66, Color(86, 104, 86, 255), 0, 0)

		if(currentclipsize > 0.8*maxclipsize)then
			weight="HEAVY"
		elseif(currentclipsize >0.4*maxclipsize) then
			weight="MEDIUM"
		elseif(currentclipsize>0) then 
			weight="LIGHT"
		else
			weight="EMPTY"
		end			
	else
		weight="MELEE"
	
	end

	draw.SimpleText(weight, "ScoreboardText", HUDx+10, HUDy+10, Color(86, 104, 86, 255), 0, 0) //text
end

hook.Add("HUDPaint","DrawAmmoHUD",DrawGunAmmo)


function doorInfo()
	local trace=LocalPlayer():GetEyeTrace()

	if(!trace.Entity:IsValid()) then return end
	if(!trace.Entity:IsDoor()) then	return	end

	if(trace.StartPos:Distance(trace.HitPos) >300) then return end
	local Owner="No Owner"
	//HasOwner	

	if(player.GetByID(trace.Entity:GetNWInt("OwnerID")):IsPlayer()) then
		Owner=player.GetByID(trace.Entity:GetNWInt("OwnerID")):Name()
	end

	draw.SimpleText("Owned By:", "ScoreboardText", trace.HitPos:ToScreen().x, trace.HitPos:ToScreen().y+13, Color(0, 200, 0, 200), 1, 1) //text
	draw.SimpleText(Owner, "ScoreboardText", trace.HitPos:ToScreen().x, trace.HitPos:ToScreen().y+30, Color(0, 200, 0, 200), 1, 1) //text
end
	
	
hook.Add("HUDPaint","DrawDoorInfo",doorInfo)




